<?php
namespace Apps\Front\Controllers;
use Phalcon\Mvc\Controller;
use Apps\Front\Controllers\ControllerBase;
use Apps\Model\User;
use Phalcon\Filter as Filter;

class LoginController extends ControllerBase{

  
    public function loginokAction(){
      $this->view->disable();
      $tel=$this->request->getPost("tel","int");
      $pwd=$this->request->getPost("pwd","string");
      //过滤空格
      $filter = new Filter();
      $tel = $filter->sanitize($tel, "trim");
      $pwd = $filter->sanitize($pwd, "trim");
      //把验证码转变成小写
      $code=strtolower($this->request->getPost("code","string"));
      if(md5($code)!=$this->session->get('code')){
        $this->jump('Index/index','验证码错误');
        return;
      }
      
      if(empty($pwd) || empty($tel)){
      	$this->jump('Index/index','手机号和密码不能为空');
      	return;
      }

      $row=User::findFirst("tel=$tel");
      if($row){
          if($row->pwd==md5($pwd)){

            //把登陆者的info放入session中
             $this->session->set('operator',$row);
             $this->jump('Index/index','登陆成功');
          }else{
             $this->jump('Index/index','密码错误');
             return;
          }
      }
      $this->jump('Index/index','手机号没有注册');
      return;  
    }

    public function exitloginAction(){
       $this->session->remove('operator');
       $this->response->redirect('Index/index');
       return;  
    } 

   
}
?>